package com.hnucm.c201901020241.my;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.hnucm.c201901020241.R;
import com.hnucm.c201901020241.utils.CircleImageView;

public class Dialog3Activity extends Activity implements View.OnClickListener {
    private Button btnSubmit;
    ImageView girl,boy;
    int op;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog3);
        //点击空白处让Activity消失，可在Style中设置
        setFinishOnTouchOutside(true);
        setWindow();
        girl=findViewById(R.id.girl);
        boy=findViewById(R.id.boy);
        girl.setOnClickListener(this);
        boy.setOnClickListener(this);
        new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
//                InputMethodManager inputMethodManager=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//                inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                return false;
            }
        }).sendEmptyMessageDelayed(0, 300);
        btnSubmit = (Button) findViewById(R.id.btn_submit);
        btnSubmit.setOnClickListener(this);
    }

    private void setWindow() {
        //窗口对齐屏幕宽度
        Window win = this.getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.CENTER;//设置对话框置顶显示
        win.setAttributes(lp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_submit:
//                在这里写提交的事件
                String choose1;
                if(op==1)choose1="男";
                else choose1="女";
                Toast.makeText(this, choose1, Toast.LENGTH_SHORT).show();
                Intent intent = getIntent();
                String choose=intent.getStringExtra("choose");
                intent.putExtra("op",choose1);
                intent.putExtra("choose","sex");
                setResult(1, intent);
                finish();
                break;
            case R.id.boy:
                boy.setSelected(true);
                girl.setSelected(false);
                op=1;
                break;
            case R.id.girl:
                girl.setSelected(true);
                boy.setSelected(false);
                op=2;
                break;
        }
    }
}